<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证码测试</title>
    <link rel="stylesheet" href="/tac/css/loading.css" />
    <script src="/tac/js/load.min.js"></script>
</head>
<body>
    <div id="captcha">

    </div>
    <button id="show">显示验证码</button>
    <script>
        let tacApp = null
        const baseUrl = 'http://127.0.0.1:8000'
        const config = {
            // 生成接口
            requestCaptchaDataUrl: baseUrl + "/captcha/get?type=RANDOM",
            // 验证接口
            validCaptchaUrl: baseUrl + "/captcha/check",
            // 验证码绑定的div块
            bindEl: "#captcha",
            validFail: (res, c, tac) => {
                tac.reloadCaptcha();
            },
            // 验证成功回调函数
            validSuccess: (res, c, tac) => {
                tac.destroyWindow();
                alert('验证成功')
            }
        }

        window.initTAC('/tac', config, {}).then((app) => {
            tacApp = app
        })

        const showBtn = document.getElementById('show')
        showBtn.addEventListener('click', () => {
            tacApp.init()
        })
    </script>
</body>
</html>